/**
 * Anderground project - Subway maps processor application.
 * Copyright (C) 2008-2009 Eldar Abusalimov, Ilya Shurigyn
 * 
 * This file is part of Anderground.
 * 
 * Anderground is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * Anderground is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Anderground.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.anderground.modules.storage.xml;

import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;

import org.anderground.core.model.ModelData;
import org.anderground.core.storage.ModelReader;
import org.anderground.core.storage.ModelWriter;

/**
 * Provides common XML constants used by {@link XmlModelReader} and
 * {@link XmlModelWriter}.
 * 
 * @author Eldar Abusalimov
 */
public final class XmlModelStorage {

	public static final String ATTR_ANGLE = "angle";
	public static final String ATTR_CLOSE = "close";
	public static final String ATTR_COLOR = "color";
	public static final String ATTR_COUNTRY_CODE = "code";
	public static final String ATTR_DX = "dx";
	public static final String ATTR_DY = "dy";
	public static final String ATTR_FROM = "from";
	public static final String ATTR_ID = "id";
	public static final String ATTR_LAST_MODIFIED = "last-modified";
	public static final String ATTR_LATITUDE = "latitude";
	public static final String ATTR_LINE = "line";
	public static final String ATTR_LONGITUDE = "longitude";
	public static final String ATTR_OPEN = "open";
	public static final String ATTR_SMOOTH = "smooth";
	public static final String ATTR_TIME = "time";
	public static final String ATTR_TO = "to";
	public static final String ATTR_VERSION = "version";
	public static final String ATTR_VISIBLE = "visible";
	public static final String ATTR_X = "x";
	public static final String ATTR_Y = "y";

	public static final String TAG_ALIAS = "alias";
	public static final String TAG_AUTHOR = "author";
	public static final String TAG_AUTHORS = "authors";
	public static final String TAG_CITY = "city";
	public static final String TAG_CONTENT = "content";
	public static final String TAG_COUNTRY = "country";
	public static final String TAG_DESCRIPTION = "description";
	public static final String TAG_EMAIL = "email";
	public static final String TAG_LINE = "line";
	public static final String TAG_LINES = "lines";
	public static final String TAG_LOCATION = "location";
	public static final String TAG_NAME = "name";
	public static final String TAG_NOTE = "note";
	public static final String TAG_POSITION = "position";
	public static final String TAG_ROOT = "map";
	public static final String TAG_SCHEDULE = "schedule";
	public static final String TAG_STATION = "station";
	public static final String TAG_STATIONS = "stations";
	public static final String TAG_TRANSFER = "transfer";
	public static final String TAG_TRANSFERS = "transfers";
	public static final String TAG_TUNNEL = "tunnel";
	public static final String TAG_TUNNELS = "tunnels";

	public static final String VERSION_0_1 = "0.1";
	public static final String VERSION_0_2 = "0.2";
	public static final String VERSION_0_3 = "0.3";
	public static final String VERSION_0_4 = "0.4";
	public static final String VERSION_0_5 = "0.5";
	public static final String VERSION_0_6 = "0.6";

	public static final String DATE_PATTERN = "dd.MM.yyyy";

	/**
	 * Creates a new {@link XmlModelReader} that uses the specified {@link File}
	 * for the future reading.
	 * 
	 * @param file
	 *            the file to read from
	 * 
	 * @return {@link ModelReader} implementation instance
	 */
	public static ModelReader createReader(File file) {
		return new SaxModelReader(file);
	}

	/**
	 * Constructs a new {@link SaxModelReader} that uses a {@link File} created
	 * by converting the specified path string.
	 * 
	 * @param path
	 *            the path of a file to read a data from
	 * 
	 * @return {@link ModelReader} implementation instance
	 */
	public static ModelReader createReader(String path) {
		return new SaxModelReader(path);
	}

	/**
	 * Creates a new {@link XmlModelReader} that uses the specified
	 * {@link InputStream} for the future reading.
	 * 
	 * @param inputStream
	 *            the stream to read from
	 * @param closeAfterRead
	 *            defines whether to close the stream after
	 *            {@link ModelReader#read()} completes
	 * 
	 * @return {@link ModelReader} implementation instance
	 */
	public static ModelReader createReader(InputStream inputStream,
			boolean closeAfterRead) {
		return new SaxModelReader(inputStream, closeAfterRead);
	}

	/**
	 * Creates a new {@link XmlModelWriter} instance that uses the specified
	 * {@link File} for the future writing.
	 * 
	 * @param file
	 *            the file to write to
	 * 
	 * @return {@link ModelWriter} implementation instance
	 */
	public static ModelWriter createWriter(File file) {
		return new DomModelWriter(file);
	}

	/**
	 * Constructs a new {@link XmlModelWriter} that uses a {@link File} created
	 * by converting the specified path string.
	 * 
	 * @param path
	 *            the path of a file to write a data to
	 * 
	 * @return {@link ModelWriter} implementation instance
	 */
	public static ModelWriter createWriter(String path) {
		return new DomModelWriter(path);
	}

	/**
	 * Creates a new {@link XmlModelWriter} instance that uses the specified
	 * {@link OutputStream} for the future writing.
	 * 
	 * @param outputStream
	 *            the stream to write to
	 * @param closeAfterWrite
	 *            defines whether to close the stream after
	 *            {@link ModelWriter#write(ModelData)} completes
	 * 
	 * @return {@link ModelWriter} implementation instance
	 */
	public static ModelWriter createWriter(OutputStream outputStream,
			boolean closeAfterWrite) {
		return new DomModelWriter(outputStream, closeAfterWrite);
	}

	/**
	 * 
	 */
	private XmlModelStorage() {
	}

}
